﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using System.Runtime.InteropServices;
namespace com.lib.manager
{
   public class PlatformManager:MonoBehaviour
    {
       public static PlatformManager Instance = null;

       public PlatformType m_plat = PlatformType.Editor;

       [DllImport("__Internal")]
       private static extern int CallIos(object data);

        void Awake()
        {
            Instance = this;
            Init();
        }

           /// <summary>
           /// 接受函数
           /// </summary>
           /// <param name="o"></param>
        public void Receive(object o)
        {


        }

       /// <summary>
       /// SDK 数据
       /// </summary>
       /// <param name="data"></param>
        public void AddSdkMsg(object data)
        {
            switch (m_plat)
            {
                case PlatformType.Android:

                    AndroidCall(data);

                    break;

                case PlatformType.IOS:

                    IOSCall(data);

                    break;
            }
        }

       /// <summary>
       /// 安卓调用
       /// </summary>
       /// <param name="data"></param>
        private void AndroidCall(object data)
        {
            #if UNITY_ANDROID
                        using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
                        {

                            using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
                            {
                                jo.Call("CallAndroid", data);

                            }
                        }

            #endif
        }

        private void IOSCall(object data)
        {
            CallIos(data);

        }


        private void Init()
        {
            switch (Application.platform)
            {
                case RuntimePlatform.Android:

                    m_plat = PlatformType.Android;
                    break;
                case RuntimePlatform.IPhonePlayer:

                    m_plat = PlatformType.IOS;
                    break;

                default:

                    m_plat = PlatformType.Editor;

                    break;
            }
        }

    }

  
}
public enum PlatformType
{
    IOS = 0,
    Android = 1,
    Editor = 2,

}